package edu.gatech.cs2340.OregonTrail;

import java.util.Iterator;

import javax.swing.JOptionPane;

import edu.gatech.cs2340.OregonTrail.EventSystem.ActorEvent;
import edu.gatech.cs2340.OregonTrail.EventSystem.PlayerInventoryModifiedEvent;


/**
 * Represent the concrete implementation of player as a Farmer profession
 * @author Won Taek Chung
 * @version 1.0.1
 */
public class Farmer extends Player {
	private int money; 
	private double breakC;
	private double sickC;
	private String name;
	private eStatus status;

	/**
	 * Default constructor for Farmer class
	 * @param name Name to use for player
	 */
	public Farmer(String name)
	{
		this.setMoney(400);
		this.setBreakC(0.7);
		this.setSickC(0.2);
		this.setName(name);
		this.setStatus(eStatus.alive);

	}
	@Override
	public String toString() {
		return "Farmer";
	}
	public void setSickC(double sickC) {
		this.sickC = sickC;
	}
	
	public double getSickC(){
		return sickC;
	}

	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#getName()
	 */
	public String getName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#setName(java.lang.String)
	 */
	public void setName(String name) {
		this.name = name;
	}

	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#getBreakC()
	 */
	public double getBreakC() {
		return breakC;
	}

	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#setBreakC(int)
	 */
	public void setBreakC(double breakC) {
		this.breakC = breakC;
	}

	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#getMoney()
	 */
	public int getMoney() {
		return money;
	}

	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#setMoney(int)
	 */
	public void setMoney(int money) {
		this.money = money;
	}

	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#getStatus()
	 */
	public eStatus getStatus(){
		return status;
	}


	/* (non-Javadoc)
	 * @see edu.gatech.cs2340.OregonTrail.Player#setStatus(edu.gatech.cs2340.OregonTrail.eStatus)
	 */
	public void setStatus(eStatus status) {
		this.status = status;

	}

	@Override
	public void actorActionPerformed(ActorEvent e) {
		if (e.getClass() == PlayerInventoryModifiedEvent.class){
			if(money < ((PlayerInventoryModifiedEvent) e).getTotalCost()){
				JOptionPane.showMessageDialog(null, "Not enough funds");
			}else if(((PlayerInventoryModifiedEvent) e).getTotalWeight() + inventory.getCurrentWeight() > inventory.getMAX_WEIGHT()){
				JOptionPane.showMessageDialog(null, "I can't carry that");
			}else{
				Iterator<Item> it = ((PlayerInventoryModifiedEvent) e).getItemAmounts().keySet().iterator();
				Item nextItem = null;
				while(it.hasNext()){
					nextItem = it.next();
					inventory.addItem(nextItem, ((PlayerInventoryModifiedEvent) e).getItemAmounts().get(nextItem));
				}
				money -= ((PlayerInventoryModifiedEvent) e).getTotalCost();
				((PlayerInventoryModifiedEvent) e).updatePlayerInfo(money, inventory.getCurrentWeight(), inventory.getStock());
			}
		}
	}
}
